<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 6.3.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/personalBlog/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/personalBlog/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/personalBlog/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/personalBlog/images/logo.svg" color="#222">

<link rel="stylesheet" href="/personalBlog/css/main.css">


<link rel="stylesheet" href="/personalBlog/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"tobylinn.github.io","root":"/personalBlog/","scheme":"Muse","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="BOM 浏览器对象模型 Browser Object Model, 流浪其对象模型提供独立的 API,可以和浏览器窗口进行交互,BOM 由多个对象组成,其中 window 对象就是 BOM 的顶层对象,其余的对象都是 window 的子对象">
<meta property="og:type" content="article">
<meta property="og:title" content="BOM">
<meta property="og:url" content="https://tobylinn.github.io/personalBlog/4090752603/index.html">
<meta property="og:site_name" content="Toby&#39;s Blog">
<meta property="og:description" content="BOM 浏览器对象模型 Browser Object Model, 流浪其对象模型提供独立的 API,可以和浏览器窗口进行交互,BOM 由多个对象组成,其中 window 对象就是 BOM 的顶层对象,其余的对象都是 window 的子对象">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2023-10-27T06:12:23.000Z">
<meta property="article:modified_time" content="2023-10-27T16:48:41.281Z">
<meta property="article:author" content="Toby Lin">
<meta property="article:tag" content="BOM">
<meta property="article:tag" content="javascript">
<meta property="article:tag" content="浏览器">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://tobylinn.github.io/personalBlog/4090752603/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>BOM | Toby's Blog</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/personalBlog/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Toby's Blog</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/personalBlog/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/personalBlog/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://tobylinn.github.io/personalBlog/4090752603/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/personalBlog/images/avatar.gif">
      <meta itemprop="name" content="Toby Lin">
      <meta itemprop="description" content="無限進步!">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Toby's Blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          BOM
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2023-10-27 14:12:23" itemprop="dateCreated datePublished" datetime="2023-10-27T14:12:23+08:00">2023-10-27</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2023-10-28 00:48:41" itemprop="dateModified" datetime="2023-10-28T00:48:41+08:00">2023-10-28</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/personalBlog/categories/JavaScript/" itemprop="url" rel="index"><span itemprop="name">JavaScript</span></a>
                </span>
                  ，
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/personalBlog/categories/JavaScript/4-BOM/" itemprop="url" rel="index"><span itemprop="name">4.BOM</span></a>
                </span>
            </span>

          <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>3.5k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>6 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h2 id="BOM"><a href="#BOM" class="headerlink" title="BOM"></a>BOM</h2><blockquote>
<p>浏览器对象模型 Browser Object Model, 流浪其对象模型提供独立的 API,可以和浏览器窗口进行交互,BOM 由多个对象组成,其中 window 对象就是 BOM 的顶层对象,其余的对象都是 window 的子对象</p>
</blockquote>
<span id="more"></span>

<h3 id="BOM-1"><a href="#BOM-1" class="headerlink" title="BOM"></a>BOM</h3><ul>
<li>window 对象</li>
</ul>
<blockquote>
<p>概念:<br>BOM 的核心对象,它是浏览器的一个实例(对象),window 有两个角色,子啊 js 里面访问浏览器的时候它是一个 api 接口,在 ECMAScript 使规范全局对象(Global)</p>
</blockquote>
<blockquote>
<p>注意:<br>所有 js 全局对象 函数 变量都会自动成为 window 的成员(除了 let&#x2F;const)</p>
</blockquote>
<ul>
<li>消息提示框</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="title function_">alert</span>(<span class="string">&quot;&quot;</span>);</span><br><span class="line"><span class="variable language_">window</span>.<span class="title function_">alert</span>(<span class="string">&quot;&quot;</span>);</span><br></pre></td></tr></table></figure>

<ul>
<li>输入框</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="title function_">prompt</span>(<span class="string">&quot;&quot;</span>);</span><br><span class="line"><span class="variable language_">window</span>.<span class="title function_">prompt</span>(<span class="string">&quot;&quot;</span>);</span><br></pre></td></tr></table></figure>

<ul>
<li>定时器</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">windows.<span class="built_in">setInterval</span>(<span class="function">() =&gt;</span> &#123;&#125;, interval);</span><br><span class="line">windows.<span class="built_in">setTimeout</span>(<span class="function">() =&gt;</span> &#123;&#125;, timeout);</span><br></pre></td></tr></table></figure>

<ul>
<li>确认框</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">windows.<span class="title function_">confirm</span>(<span class="string">&quot;确认要删除吗&quot;</span>);</span><br></pre></td></tr></table></figure>

<ul>
<li>打开新闻页</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable language_">window</span>.<span class="title function_">open</span>(<span class="string">&quot;https://www.baidu.com&quot;</span>, <span class="string">&quot;_blank&quot;</span>, <span class="string">&quot;width=100,height=100&quot;</span>);</span><br></pre></td></tr></table></figure>

<ul>
<li><p>document 对象(文档对象)</p>
</li>
<li><p>location 对象(浏览器当前的 URL 对象)</p>
</li>
</ul>
<blockquote>
<p>概念:<br>获取当前浏览器请求网址消息,控制&#x2F;获取请求地址的消息</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// window子对象</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="variable language_">window</span>.<span class="property">location</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 重定向到新页面(没有历史记录，不能回退到上一页,一打开就重定向，如果不是立刻跳转，才会出现历史记录)</span></span><br><span class="line"><span class="built_in">setTimeout</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">  location.<span class="property">href</span> = <span class="string">&quot;https://www.baidu.com&quot;</span>;</span><br><span class="line">&#125;, <span class="number">3000</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">// url 统一资源定位器</span></span><br><span class="line"><span class="comment">// 返回 url 的端口</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(location.<span class="property">port</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 返回 url 的完整信息</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(location.<span class="property">origin</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 返回http协议</span></span><br><span class="line"><span class="comment">// HTTP协议是用于从服务器传输文本到本地浏览器的传输协议</span></span><br><span class="line"><span class="comment">// http / https</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(location.<span class="property">protocol</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 返回 hash 哈希值</span></span><br><span class="line"><span class="comment">// 返回url后面携带 # 的字符串，哈希值的修改不会引起页面的属性</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&quot;location.hash&quot;</span>, location.<span class="property">hash</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 返回域名和端口号</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(location.<span class="property">host</span>);</span><br><span class="line"><span class="comment">// 返回域名(在http：//域名:端口号)</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(location.<span class="property">hostname</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 返回目录和文件名 (端口之后为目录和文件名)</span></span><br><span class="line"><span class="comment">// /location.html</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(location.<span class="property">pathname</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 获取url ‘？’ 后面的参数值</span></span><br><span class="line"><span class="comment">// http://127.0.0.1:3886/location.html?name=hy#login</span></span><br><span class="line"><span class="comment">// ?name=hy</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(location.<span class="property">search</span>);</span><br></pre></td></tr></table></figure>

<ul>
<li>navigator 对象(浏览器本身信息)</li>
</ul>
<blockquote>
<p>概念:<br>返回浏览器的信息,包括浏览器语言&#x2F;系统类型&#x2F;版本等等</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 操作系统的类型 Win32</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(navigator.<span class="property">platform</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 浏览器的名称</span></span><br><span class="line"><span class="comment">// 出于兼容问题，所有现代浏览器都会返回 Netscape</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(navigator.<span class="property">appName</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 浏览器的语言</span></span><br><span class="line"><span class="comment">// zh-CH 代表的是语言文化代码和国家地区</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(navigator.<span class="property">language</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 浏览器的版本 （可能被启用）</span></span><br><span class="line"><span class="comment">//5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(navigator.<span class="property">appVersion</span>);</span><br><span class="line"><span class="comment">// alert(navigator.appVersion);</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 浏览器的信息（版本、设备、内核）</span></span><br><span class="line"><span class="comment">// Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(navigator.<span class="property">userAgent</span>);</span><br></pre></td></tr></table></figure>

<ul>
<li>screen 对象(浏览器屏幕消息)</li>
</ul>
<blockquote>
<p>注意:<br>浏览器的屏幕和系统任务栏有关</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 返回屏幕的有效高度(不包括系统的任务栏)</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(screen.<span class="property">availHeight</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 返回屏幕的有效宽度(不包括系统的任务栏)</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(screen.<span class="property">availWidth</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 返回屏幕的高度</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(screen.<span class="property">height</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 返回屏幕的宽度</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(screen.<span class="property">width</span>);</span><br></pre></td></tr></table></figure>

<ul>
<li>history 对象(浏览器历史记录)</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 查询历史记录（网址数量）</span></span><br><span class="line"><span class="comment">// IE、Opena 记录从0开始，其他浏览器默认从1开始</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(history.<span class="property">length</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 加载前一个历史记录</span></span><br><span class="line">history.<span class="title function_">back</span>();</span><br><span class="line"></span><br><span class="line"><span class="comment">//加载后一个历史记录（返回下一页）</span></span><br><span class="line">history.<span class="title function_">go</span>(number);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 加载前进页历史记录（指定页数/数量）</span></span><br><span class="line"><span class="comment">// number 为正数，前进一页（下一页），负数，后退一页（上一页）</span></span><br><span class="line">history.<span class="title function_">forward</span>();</span><br></pre></td></tr></table></figure>

<h3 id="位置"><a href="#位置" class="headerlink" title="位置"></a>位置</h3><h4 id="offset-系列"><a href="#offset-系列" class="headerlink" title="offset 系列"></a>offset 系列</h4><blockquote>
<p>offset 偏移,包括这个元素在文档中所占用位置(可视&#x2F;显示)的大小</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">只读属性,不可修改</span><br><span class="line"></span><br><span class="line">1. offsetWidth</span><br><span class="line">   当前元素的实际宽度 = 左右 padding + width + 左右 border</span><br><span class="line"></span><br><span class="line">2. offsetHeight</span><br><span class="line">   当前元素的实际高度 = 上下 padding + width + 上下 border</span><br><span class="line"></span><br><span class="line">3. offsetParent</span><br><span class="line">   当前元素的父元素(position 不为 static),如果所有的元素都没有设置定位,默认根据根元素(html)定位,参照元素为 body</span><br><span class="line"></span><br><span class="line">4. offsetTop</span><br><span class="line">   当前元素距离(offsetParent 父元素)顶部的偏移值 = (offsetParent 元素的 paddingTop + 其他中间元素 offsetHeight + marginTop)</span><br><span class="line"></span><br><span class="line">5. offsetLeft</span><br><span class="line">   当前元素距离(offsetParent 父元素)左边的偏移值 = (offsetParent 元素的 paddingLeft + 其他中间元素 offsetWidth + marginLeft)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="client-系列"><a href="#client-系列" class="headerlink" title="client 系列"></a>client 系列</h4><blockquote>
<p>指元素本身的可视内容,不包括(border、滚动条、超出内容被隐藏部分)</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">1. clientWidth</span><br><span class="line">   当前元素的可视宽度 = (width + 左右 padding)</span><br><span class="line"></span><br><span class="line">2. clientHeight</span><br><span class="line">   当前元素的可视高度 = (height + 上下 padding)</span><br><span class="line"></span><br><span class="line">3. clientTop</span><br><span class="line">   当前元素的上边框 = (上 border)</span><br><span class="line"></span><br><span class="line">4. clientLeft</span><br><span class="line">   当前元素的左边框 = (左 border)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="scroll-系列"><a href="#scroll-系列" class="headerlink" title="scroll 系列"></a>scroll 系列</h4><blockquote>
<p>指元素滚动,包括这个元素没显示出来的实际宽度和高度,包括 padding, 不包括(border、滚动条)</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">1. scrollWidth</span><br><span class="line">   当前元素的滚动区域宽度(相当于 slientWidth)</span><br><span class="line">   width(内容实际宽度) + 左右 padding</span><br><span class="line"></span><br><span class="line">2. scrollHeight</span><br><span class="line">   当前元素的滚动区域高度(相当于 slientHeight)</span><br><span class="line">   width(内容实际高度) + 上下 padding</span><br><span class="line"></span><br><span class="line">3. scrollTop</span><br><span class="line">   当前元素向上卷出的内容高度(当前元素最顶端和可视区域最顶端之间的距离)</span><br><span class="line">   简单理解:被隐藏的距离(内容上部分的内容)</span><br><span class="line"></span><br><span class="line">4. scrollLeft</span><br><span class="line">   当前元素向左卷出的内容宽度(当前元素最左端和可视区域最左端之间的距离)</span><br><span class="line">   简单理解:被隐藏的距离(内容左部分的内容)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/personalBlog/tags/BOM/" rel="tag"># BOM</a>
              <a href="/personalBlog/tags/javascript/" rel="tag"># javascript</a>
              <a href="/personalBlog/tags/%E6%B5%8F%E8%A7%88%E5%99%A8/" rel="tag"># 浏览器</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item"></div>
      <div class="post-nav-item">
    <a href="/personalBlog/4150170345/" rel="next" title="DOM">
      DOM <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#BOM"><span class="nav-number">1.</span> <span class="nav-text">BOM</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#BOM-1"><span class="nav-number">1.1.</span> <span class="nav-text">BOM</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%BD%8D%E7%BD%AE"><span class="nav-number">1.2.</span> <span class="nav-text">位置</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#offset-%E7%B3%BB%E5%88%97"><span class="nav-number">1.2.1.</span> <span class="nav-text">offset 系列</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#client-%E7%B3%BB%E5%88%97"><span class="nav-number">1.2.2.</span> <span class="nav-text">client 系列</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#scroll-%E7%B3%BB%E5%88%97"><span class="nav-number">1.2.3.</span> <span class="nav-text">scroll 系列</span></a></li></ol></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">Toby Lin</p>
  <div class="site-description" itemprop="description">無限進步!</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/personalBlog/archives/">
        
          <span class="site-state-item-count">2</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/personalBlog/categories/">
        <span class="site-state-item-count">3</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/personalBlog/tags/">
        <span class="site-state-item-count">6</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>
      

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Toby Lin</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-area"></i>
    </span>
    <span title="站点总字数">7k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">12 分钟</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://muse.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/personalBlog/lib/anime.min.js"></script>
  <script src="/personalBlog/lib/velocity/velocity.min.js"></script>
  <script src="/personalBlog/lib/velocity/velocity.ui.min.js"></script>

<script src="/personalBlog/js/utils.js"></script>

<script src="/personalBlog/js/motion.js"></script>


<script src="/personalBlog/js/schemes/muse.js"></script>


<script src="/personalBlog/js/next-boot.js"></script>




  















  

  

</body>
</html>
